home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 2120 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.2 KB

  1. Path: news.mindlink.net!news
  2. From: genew@mindlink.bc.ca (Gene Wirchenko)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: What should be returned?
  5. Date: Fri, 19 Jan 1996 06:53:14 GMT
  6. Organization: MIND LINK! - British Columbia, Canada
  7. Message-ID: <4dnf7d$1sa@fountain.mindlink.net>
  8. References: <4dj8pv$cjd@eng_ser1.erg.cuhk.hk> <30fd5c1a.5495936@nntp.ix.netcom.com>
  9. NNTP-Posting-Host: line121.nwm.mindlink.net
  10. X-Newsreader: Forte Free Agent 1.0.82
  11.  
  12. miker3@ix.netcom.com (Mike Rubenstein) wrote:
  13.  
  14. >phsung@cs.cuhk.hk (the CAReLess boy) wrote:
  15.  
  16. >|>Hi, all,
  17. >|>
  18. >|>    It's said that the function main must return an integer value
  19. >|>but I just don't know what value should be returned.  Also, if I
  20. >quit
  21. >|>main by exit(), what's the use of the return value?
  22. >|>
  23. >|>    Any help?
  24.  
  25.      0, EXIT_SUCCESS, EXIT_FAILURE.  I think I spelled the last two
  26. right.  Score two points each when you find them in your manual.
  27.  
  28. >If you always use exit() from main, you need not have a return
  29. >statement.  For example, the following is legal:
  30.  
  31. >    #include <stdlib.h>
  32. >    int main(void)
  33. >    {
  34. >      exit(0);
  35. >    }
  36.  
  37. >In fact, it's even legal to have neither a return or exit():
  38.  
  39. >    int main(void)
  40. >    {
  41. >    }
  42.  
  43. >This will return an undefined value to the operating environment, but
  44. >does not result in undefined behavior and will not do damage.  I
  45.  
  46.      Returning an undefined value doesn't result in undefined
  47. bahavior?  You been smokin' sumthin' funny, boy?
  48.      What happens if/when the return value is interrogated as in
  49. MS-DOS's ERRORLEVEL or <other OS>'s <appropriate feature>?
  50.  
  51. >strongly recommend against this practice and many compilers will issue
  52. >a warning message.
  53.  
  54. >What is not legal is to define main as returning a type other than
  55. >int.  The above would be illegal if main were defined as void
  56. >main(void).  Defining main as returing anything but int results in
  57. >undefined behavior; the standard allows the compiler to do anything
  58. >(format your disk, send email to your boss complaining about your
  59. >incompetence, ...).
  60.  
  61.       void main() almost has a defined result: it gets you flamed in
  62. comp.lang.c <G>.
  63.  
  64. >Michael M Rubenstein
  65.  
  66. Sincerely,
  67.  
  68. Gene Wirchenko
  69.  
  70. C Pronunciation Guide:
  71.      y=x++;     "wye equals ex plus plus semicolon"
  72.      x=x++;     "ex equals ex doublecross semicolon"
  73.  
  74.